﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class UIKD : ViewBase
    {
        public TDRAUFTR cDR
        {
            get
            {
                return (TDRAUFTR)this.FindName("cDR");
            }
        }
        public UIKD()
        {

        }
        /// <summary>
        /// SetProd 当前订单
        /// SetData保存所有订单，但是用于展示今日订单
        /// SetEnv保存所有订单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        public void KD0Command(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            TMV.SetUpNewRow(ref dwData);
            dwData["KDSTAKZ"] = "A";
            dwData["KDKUNDNA"] = "KD0".PadRight(8);
            dwData["KDNAME1"] = "KD0".PadRight(40);
            dwData["KDKUNDNR"] = "00000000";
            dwData["KDKREDLIM1"] = 999999999;
            TMV.Insert(dwData);
            vwMaster.View.MoveCurrentToFirst();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            try
            {
                dwKD = dwMaster;
                KDNAME1 = TMV.KDNAME1;
                KDNAME2 = TMV.KDNAME2;
                KDSTRASSE1 = TMV.KDSTRASSE1;
                KDSTRASSE2 = TMV.KDSTRASSE2;
                KDSTRASSE2 = TMV.KDSTRASSE2;
                KDPOSTFACH = TMV.KDPOSTFACH;
                KDPOSTFACH = TMV.KDPOSTFACH;
                KDTEL = TMV.KDTEL;
                KDTTEX = TMV.KDTTEX;
                KDFAX = TMV.KDFAX;
                if (dwMaster != null)
                {
                    KEY = dwMaster["KDKUNDNR"].ToString();
                    KDKNAME = dwMaster["KDKUNDNA"].ToString();
                }
                else
                {
                    KEY = "";
                    KDKNAME = "";
                }
                if (dwMaster != null)
                {
                    KEY = dwMaster["KDKUNDNR"].ToString();
                    KD15KEY = dwMaster["KDKUNDNR"].ToString() + "VK".PadRight(8);//先通知新建
                    KVKEY = TMV.KDKUNDNR + "   " + "001";
                    已付款 = Convert.ToDouble(dwMaster["KDVERSUMLTO"].ToString());
                    待处理现金 = Convert.ToDouble(dwMaster["KDAUFBEST"].ToString());
                    已开票 = Convert.ToDouble(dwMaster["KDVERSUML"].ToString());
                    
                }
                else
                {
                    KVKEY = "";
                    KD15KEY = "";
                    已付款 = 0;
                    待处理现金 = 0;
                    已开票 = 0;
                    KEY = "";
                }
            }
            catch (Exception ex)
            {
                //Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void VR02Command(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.VR02(RUNID, "K".PadRight(30));
        }

        public void VK02Command(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.VK02(RUNID);
        }
        public virtual void OnKDBLOCKChg(bool value)
        {
            if (!value)
                return;
            dwData = TMV.VK.TBMain.NewRow();
            dwData["VKKMANDANT"] = app.Mandant; ;
            dwData["VKKKUNDNR"] = KEY;
            SResult = TMV.VK.QueryVKKOPF(dwData, 3);
            TBTemp = TMV.VK.TBMain.Clone();
            TBTemp.Merge(SResult.Tables[0]);
            string vkblock = "";
            foreach (DataRow row in TBTemp.Rows)
            {
                vkblock = "K" + row["VKKAUFKRS"].ToString() + row["VKKAUFLFD"].ToString();
                if (row["VKKKDSTA"].ToString() == "11") break;
                row["VKKKDSTA"] = 11;
                TMV.VK.UpdateVKKOPF(row, app.company, 6);
                break;
            }
            VKBLOCK = vkblock;
        }
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            PM["KUNDNR"] = dwMaster["KDKUNDNR"].ToString();
            vwMaster.View.MoveCurrentTo(-1);
            ((VKDSTAMM)MV).KDDEL(PM);
            vwMaster.View.MoveCurrentToFirst();
            base.DeleteCommand(sender, e);
        }

        public virtual void On已开票Chg(double value)
        {
            if (MV == null)
                return;
            if (dwMaster == null)
                return;
            TMV.KDVERSUML = value;
            SWING = 已开票 - (待处理现金 + 已付款);
            CREDIT = ((VKDSTAMM)MV).KDKREDLIM1 - SWING;
        }

        public virtual void On待处理现金Chg(double value)
        {
            if (MV == null)
                return;
            if (dwMaster == null)
                return;
            TMV.KDAUFBEST = value;
            TMV.UpdateKDSTAMM(dwMaster, 0);
            //SWING = 已开票 - (待处理现金 + 已付款);
            SWING = 已开票 - (待处理现金);
            CREDIT = ((VKDSTAMM)MV).KDKREDLIM1 - SWING;
        }

        public virtual void On已付款Chg(double value)
        {
            if (MV == null)
                return;
            if (dwMaster == null)
                return;
            TMV.KDVERSUMLTO = value;
            SWING = 已开票 - (待处理现金);
            CREDIT = ((VKDSTAMM)MV).KDKREDLIM1 - SWING;
        }

        public virtual void OnCREDITChg(double value)
        {
            if (MV == null)
                return;
            if (dwMaster == null)
                return;
            if (value < 0)
            {
                TMV.KDSPLIEFKZ = "J";
                KDBLOCK = true;
            }
            else
            {
                TMV.KDSPLIEFKZ = " ";
                KDBLOCK = false;
            }

        }


        public override void OnSave()
        {
            if (!IsSaved)
                return;
            foreach (DataRow row in TBMain.Rows)
            {
                if (row.RowState == DataRowState.Unchanged) continue;
                TMV.UpdateKDSTAMM(row, 0);
            }
            if (dwMaster == null)
                return;
            PM["KUNDNR"] = dwMaster["KDKUNDNR"].ToString();
            TMV.KDUPDATE(PM);
            string _key = KEY;
            KEY = "";
            KEY = _key;//触发关联界面更改
            base.OnSave();
        }
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            IsSaved = false;
            PM["KDSTAKZ"] = "A";
            PM["KDKUNDNA"] = " ";
            PM["KDNAME1"] = " ";
            ((VKDSTAMM)MV).KDNEW(PM);
            vwMaster.View.MoveCurrentToFirst();
            base.NewCommand(sender, e);
        }

        public override void CopyCommand(object sender, RoutedEventArgs e)
        {
            if (dwKD == null)
                return;
            DataRow dwData = TBMain.NewRow();
            dwData.ItemArray = dwMaster.ItemArray;
            dwData["KDSTAKZ"] = "A";
            LFD = VSDDAT.SD22.GETNEXT("0022", "  ", "KUNDNR");
            dwData["KDKUNDNR"] = Helpers.Helper.Right("00000000" + LFD, 8);
            dwData["KDKREDLIM1"] = 999999999;
            ((VKDSTAMM)MV).Insert(dwData);
            vwMaster.View.MoveCurrentToFirst();
            base.CopyCommand(sender, e);
        }
        public override void LOADBYAUF()
        {
            if (!IsCanLoad)
                return;
            TBMain.Clear();
            if (ORDERNUM.Length < 8)
                return;
            dwData = TBMain.NewRow();
            dwData["KDMANDANT"] = app.Mandant;
            dwData["KDKUNDNR"] = ORDERNUM.Substring(0, 8);
            SResult = TMV.QueryKDSTAMM(dwData, 1);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
        /*
        public override void LOADBYAUF()
        {
            try
            {
                if (!IsSaved)
                    return;
                if (ORDERNUM.Length < 8)
                    return;
                if (ORDERNUM != KEY)
                    return;
                dwData = TBMain.NewRow();
                dwData["KDMANDANT"] = app.Mandant;
                dwData["KDKUNDNR"] = " AND KDKUNDNR='" + ORDERNUM.Substring(0, 8) + "'";
                SResult = ((VKDSTAMM)MV).QueryKDSTAMM(dwData, 5);
                DataTable tb = TBMain.Clone();
                tb.Merge(SResult.Tables[0]);
                foreach (DataRow row in tb.Rows)
                {
                    dwMaster.ItemArray = row.ItemArray;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        */

        public virtual void ImportExcel(object sender, RoutedEventArgs e)
        {
             
            

        }
        public override void OnAppModeChg()
        {
            base.OnAppModeChg();

            switch (app.company)
            {
                case "TST":
                    switch (app.AppMode)
                    {
                        case "TISSUE":
                            VB = "TSK";
                            break;
                        case "TMODE":
                            VB = "TMK";
                            break;
                    }
                    break;
            }
        }
    }
    public partial class UIKD : ViewBase
    {

        public VKDSTAMM TMV
        {
            get
            {
                return (VKDSTAMM)MV;
            }
        }
        #region ==VB===========
        public static readonly DependencyProperty VBProperty = DependencyProperty.Register("VB",
        typeof(string), typeof(UIKD),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVBChanged));
        public string VB
        {
            get
            {
                return (string)GetValue(VBProperty);
            }
            set
            {
                SetValue(VBProperty, value);
            }
        }
        private static void OnVBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.VB = (string)e.NewValue;
            }
        }
        #endregion

        #region ==REGMWST===========
        public static readonly DependencyProperty REGMWSTProperty = DependencyProperty.Register("REGMWST",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnREGMWSTChanged));
        public string REGMWST
        {
            get
            {
                return (string)GetValue(REGMWSTProperty);
            }
            set
            {
                SetValue(REGMWSTProperty, value);
                OnREGMWSTChg(value);
            }
        }
        private static void OnREGMWSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.REGMWST = (string)e.NewValue;
            }
        }
        public virtual void OnREGMWSTChg(string value)
        {
            if (!IsEdit)
                return;
            TMV.KDREGMWST = value;
        }
        #endregion

        #region ==KD15KEY===========
        public static readonly DependencyProperty KD15KEYProperty = DependencyProperty.Register("KD15KEY",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKD15KEYChanged));
        public string KD15KEY
        {
            get
            {
                return (string)GetValue(KD15KEYProperty);
            }
            set
            {
                SetValue(KD15KEYProperty, value);
            }
        }
        private static void OnKD15KEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KD15KEY = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KVKEY===========
        public static readonly DependencyProperty KVKEYProperty = DependencyProperty.Register("KVKEY",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKVKEYChanged));
        public string KVKEY
        {
            get
            {
                return (string)GetValue(KVKEYProperty);
            }
            set
            {
                SetValue(KVKEYProperty, value);
            }
        }
        private static void OnKVKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KVKEY = (string)e.NewValue;
            }
        }
        #endregion  

        #region ==KUNDNR===========
        public static readonly DependencyProperty KUNDNRProperty = DependencyProperty.Register("KUNDNR",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKUNDNRChanged));
        public string KUNDNR
        {
            get
            {
                return (string)GetValue(KUNDNRProperty);
            }
            set
            {
                SetValue(KUNDNRProperty, value);
            }
        }
        private static void OnKUNDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KUNDNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDKNAME===========
        public static readonly DependencyProperty KDKNAMEProperty = DependencyProperty.Register("KDKNAME",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDKNAMEChanged));
        public string KDKNAME
        {
            get
            {
                return (string)GetValue(KDKNAMEProperty);
            }
            set
            {
                SetValue(KDKNAMEProperty, value);
            }
        }
        private static void OnKDKNAMEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDKNAME = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwKD===========
        public static readonly DependencyProperty dwKDProperty = DependencyProperty.Register("dwKD",
            typeof(DataRow), typeof(UIKD),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwKDChanged));
        public DataRow dwKD
        {
            get
            {
                return (DataRow)GetValue(dwKDProperty);
            }
            set
            {
                SetValue(dwKDProperty, value);
            }
        }
        private static void OdwKDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwKD = row;
            }
        }
        #endregion

        #region ==KDNAME1===========
        public static readonly DependencyProperty KDNAME1Property = DependencyProperty.Register("KDNAME1",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDNAME1Changed));
        public string KDNAME1
        {
            get
            {
                return (string)GetValue(KDNAME1Property);
            }
            set
            {
                SetValue(KDNAME1Property, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDNAME1 = value;
            }
        }
        private static void OnKDNAME1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDNAME1 = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDLAND===========
        public static readonly DependencyProperty KDLANDProperty = DependencyProperty.Register("KDLAND",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDLANDChanged));
        public string KDLAND
        {
            get
            {
                return (string)GetValue(KDLANDProperty);
            }
            set
            {
                SetValue(KDLANDProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDLAND = value;
            }
        }
        private static void OnKDLANDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDLAND = (string)e.NewValue;
            }
        }
        #endregion


        #region ==KDNAME2===========
        public static readonly DependencyProperty KDNAME2Property = DependencyProperty.Register("KDNAME2",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDNAME2Changed));
        public string KDNAME2
        {
            get
            {
                return (string)GetValue(KDNAME2Property);
            }
            set
            {
                SetValue(KDNAME2Property, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDNAME2 = value;
            }
        }
        private static void OnKDNAME2Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDNAME2 = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDSTRASSE1===========
        public static readonly DependencyProperty KDSTRASSE1Property = DependencyProperty.Register("KDSTRASSE1",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDSTRASSE1Changed));
        public string KDSTRASSE1
        {
            get
            {
                return (string)GetValue(KDSTRASSE1Property);
            }
            set
            {
                SetValue(KDSTRASSE1Property, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDSTRASSE1 = value;
            }
        }
        private static void OnKDSTRASSE1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDSTRASSE1 = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDSTRASSE2===========
        public static readonly DependencyProperty KDSTRASSE2Property = DependencyProperty.Register("KDSTRASSE2",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDSTRASSE2Changed));
        public string KDSTRASSE2
        {
            get
            {
                return (string)GetValue(KDSTRASSE2Property);
            }
            set
            {
                SetValue(KDSTRASSE2Property, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDSTRASSE2 = value;
            }
        }
        private static void OnKDSTRASSE2Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDSTRASSE2 = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDTEL===========
        public static readonly DependencyProperty KDTELProperty = DependencyProperty.Register("KDTEL",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDTELChanged));
        public string KDTEL
        {
            get
            {
                return (string)GetValue(KDTELProperty);
            }
            set
            {
                SetValue(KDTELProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDTEL = value;
            }
        }
        private static void OnKDTELChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDTEL = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDZENTR===========
        public static readonly DependencyProperty KDZENTRProperty = DependencyProperty.Register("KDZENTR",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDZENTRChanged));
        public string KDZENTR
        {
            get
            {
                return (string)GetValue(KDZENTRProperty);
            }
            set
            {
                SetValue(KDZENTRProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDZENTR = value;
            }
        }
        private static void OnKDZENTRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDZENTR = (string)e.NewValue;
            }
        }
        #endregion



        #region ==KDFAX===========
        public static readonly DependencyProperty KDFAXProperty = DependencyProperty.Register("KDFAX",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDFAXChanged));
        public string KDFAX
        {
            get
            {
                return (string)GetValue(KDFAXProperty);
            }
            set
            {
                SetValue(KDFAXProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDFAX = value;
            }
        }
        private static void OnKDFAXChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDFAX = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDPLZPOSTF===========
        public static readonly DependencyProperty KDPLZPOSTFProperty = DependencyProperty.Register("KDPLZPOSTF",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDPLZPOSTFChanged));
        public string KDPLZPOSTF
        {
            get
            {
                return (string)GetValue(KDPLZPOSTFProperty);
            }
            set
            {
                SetValue(KDPLZPOSTFProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDPLZPOSTF = value;
            }
        }
        private static void OnKDPLZPOSTFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDPLZPOSTF = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDPOSTFACH===========
        public static readonly DependencyProperty KDPOSTFACHProperty = DependencyProperty.Register("KDPOSTFACH",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDPOSTFACHChanged));
        public string KDPOSTFACH
        {
            get
            {
                return (string)GetValue(KDPOSTFACHProperty);
            }
            set
            {
                SetValue(KDPOSTFACHProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDPOSTFACH = value;
            }
        }
        private static void OnKDPOSTFACHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDPOSTFACH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDTTEX===========
        public static readonly DependencyProperty KDTTEXProperty = DependencyProperty.Register("KDTTEX",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDTTEXChanged));
        public string KDTTEX
        {
            get
            {
                return (string)GetValue(KDTTEXProperty);
            }
            set
            {
                SetValue(KDTTEXProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDTTEX = value;
            }
        }
        private static void OnKDTTEXChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDTTEX = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDMAILADR===========
        public static readonly DependencyProperty KDMAILADRProperty = DependencyProperty.Register("KDMAILADR",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDMAILADRChanged));
        public string KDMAILADR
        {
            get
            {
                return (string)GetValue(KDMAILADRProperty);
            }
            set
            {
                SetValue(KDMAILADRProperty, value);
                if (MV == null)
                    return;
                ((VKDSTAMM)MV).KDMAILADR = value;
            }
        }
        private static void OnKDMAILADRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDMAILADR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==已开票===========
        public static readonly DependencyProperty 已开票Property = DependencyProperty.Register("已开票",
            typeof(double), typeof(UIKD),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, On已开票Changed));
        public double 已开票
        {
            get
            {
                return (double)GetValue(已开票Property);
            }
            set
            {
                SetValue(已开票Property, value);

            }
        }
        private static void On已开票Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.已开票 = (double)e.NewValue;
                src.On已开票Chg((double)e.NewValue);
            }
        }
        #endregion

        #region ==待处理现金===========
        public static readonly DependencyProperty 待处理现金Property = DependencyProperty.Register("待处理现金",
            typeof(double), typeof(UIKD),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, On待处理现金Changed));
        public double 待处理现金
        {
            get
            {
                return (double)GetValue(待处理现金Property);
            }
            set
            {
                SetValue(待处理现金Property, value);

            }
        }
        private static void On待处理现金Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.待处理现金 = (double)e.NewValue;
                src.On待处理现金Chg((double)e.NewValue);
            }
        }
        #endregion

        #region ==已付款===========
        public static readonly DependencyProperty 已付款Property = DependencyProperty.Register("已付款",
            typeof(double), typeof(UIKD),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, On已付款Changed));
        public double 已付款
        {
            get
            {
                return (double)GetValue(已付款Property);
            }
            set
            {
                SetValue(已付款Property, value);

            }
        }
        private static void On已付款Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.已付款 = (double)e.NewValue;
                src.On已付款Chg((double)e.NewValue);
            }
        }
        #endregion

        #region ==SWING===========
        public static readonly DependencyProperty SWINGProperty = DependencyProperty.Register("SWING",
            typeof(double), typeof(UIKD),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSWINGChanged));
        public double SWING
        {
            get
            {
                return (double)GetValue(SWINGProperty);
            }
            set
            {
                SetValue(SWINGProperty, value);
                if (MV == null) return;
                ((VKDSTAMM)MV).SWING = value;
            }
        }
        private static void OnSWINGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.SWING = (double)e.NewValue;
            }
        }
        #endregion

        #region ==CREDIT===========
        public static readonly DependencyProperty CREDITProperty = DependencyProperty.Register("CREDIT",
            typeof(double), typeof(UIKD),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCREDITChanged));
        public double CREDIT
        {
            get
            {
                return (double)GetValue(CREDITProperty);
            }
            set
            {
                SetValue(CREDITProperty, value);

            }
        }
        private static void OnCREDITChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.CREDIT = (double)e.NewValue;
                src.OnCREDITChg((double)e.NewValue);
            }
        }
        #endregion

        #region ==KDBLOCK===========
        public static readonly DependencyProperty KDBLOCKProperty = DependencyProperty.Register("KDBLOCK",
            typeof(bool), typeof(UIKD),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDBLOCKChanged));
        public bool KDBLOCK
        {
            get
            {
                return (bool)GetValue(KDBLOCKProperty);
            }
            set
            {
                SetValue(KDBLOCKProperty, value);
                OnKDBLOCKChg(value);

            }
        }
        private static void OnKDBLOCKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.KDBLOCK = (bool)e.NewValue;
            }
        }

        #endregion

        #region ==VKBLOCK===========
        public static readonly DependencyProperty VKBLOCKProperty = DependencyProperty.Register("VKBLOCK",
            typeof(string), typeof(UIKD),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKBLOCKChanged));
        public string VKBLOCK
        {
            get
            {
                return (string)GetValue(VKBLOCKProperty);
            }
            set
            {
                SetValue(VKBLOCKProperty, value);
                OnVKBLOCKChg(value);
            }
        }
        private static void OnVKBLOCKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIKD;
            if (src != null)
            {
                src.VKBLOCK = (string)e.NewValue;
            }
        }
        public virtual void OnVKBLOCKChg(string value)
        {
        }
        #endregion
    }
}
